{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# magic command start wirh \"%\",可以看做是内置于IPython的命令行程序，可以带参数，各命令含义不同，魔术命令后加?可以看到参数的说明\n",
    "%reset?\n",
    "#但也不是每个命令都有用，这与版本和系统有关，例如在本机中，%cpaste与%paste就没有用\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 驱动器 C 中的卷没有标签。\n",
      " 卷的序列号是 0003-3A3E\n",
      "\n",
      " C:\\Users\\Administrator 的目录\n",
      "\n",
      "2015/11/08  14:26    <DIR>          .\n",
      "2015/11/08  14:26    <DIR>          ..\n",
      "2015/08/16  22:59    <DIR>          .android\n",
      "2015/10/08  16:45    <DIR>          .astropy\n",
      "2015/09/21  10:08    <DIR>          .config\n",
      "2015/09/09  16:03    <DIR>          .continuum\n",
      "2015/11/08  13:54    <DIR>          .ipynb_checkpoints\n",
      "2015/09/09  16:04    <DIR>          .ipython\n",
      "2015/09/21  10:08    <DIR>          .local\n",
      "2015/10/26  10:19    <DIR>          .matplotlib\n",
      "2015/10/08  16:39    <DIR>          .PyCharm40\n",
      "2015/08/15  16:17               172 .qt-license\n",
      "2015/09/21  10:11               218 .recently-used.xbel\n",
      "2015/10/20  10:02               134 .rediscli_history\n",
      "2015/11/07  16:51    <DIR>          .swt\n",
      "2015/11/07  15:31             8,309 A quick tour of IPython Notebook.ipynb\n",
      "2015/11/07  15:33           709,613 Chapter 1 - Reading from a CSV.ipynb\n",
      "2015/09/14  10:09    <DIR>          CMB\n",
      "2015/08/14  17:21    <DIR>          Contacts\n",
      "2015/10/19  14:32             7,710 datatime.ipynb\n",
      "2015/11/06  10:42    <DIR>          Desktop\n",
      "2015/11/05  10:55    <DIR>          Documents\n",
      "2015/08/14  17:21    <DIR>          Downloads\n",
      "2015/08/14  17:21    <DIR>          Favorites\n",
      "2015/11/08  14:26             1,332 ipython magic command.ipynb\n",
      "2015/08/14  17:21    <DIR>          Links\n",
      "2015/08/14  17:21    <DIR>          Music\n",
      "2015/10/19  16:13            57,402 pandas-test.ipynb\n",
      "2015/08/15  21:47    <DIR>          Pictures\n",
      "2015/10/08  16:42    <DIR>          PycharmProjects\n",
      "2015/08/14  16:55    <DIR>          Roaming\n",
      "2015/09/17  11:27        11,986,970 S1EP2_Scipy.ipynb\n",
      "2015/10/08  11:15             4,551 S1EP3_Iris.txt\n",
      "2015/08/14  17:21    <DIR>          Saved Games\n",
      "2015/08/14  17:21    <DIR>          Searches\n",
      "2015/10/15  17:03    <DIR>          Untitled Folder\n",
      "2015/10/15  17:03    <DIR>          Untitled Folder 1\n",
      "2015/10/08  16:02             8,485 Untitled.ipynb\n",
      "2015/10/08  10:44                 0 untitled.txt\n",
      "2015/08/14  17:21    <DIR>          Videos\n",
      "2015/10/23  11:32                78 zmq+redis.ipynb\n",
      "              13 个文件     12,784,974 字节\n",
      "              28 个目录 43,611,774,976 可用字节\n"
     ]
    }
   ],
   "source": [
    "#在命令前加！（如！dir），说明该命令在操作系统shell下执行\n",
    "!cd c:\\\\pythoncoding\n",
    "!dir"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (add.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"c:\\pythoncoding\\add.py\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    !cd c:\\\\pythoncoding\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "#把上述两条命令(!cd c:\\\\pythoncoding    !dir)放入脚本，再运行，会报错\n",
    "%run c:\\\\pythoncoding\\add.py\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "系统找不到指定的路径。\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 驱动器 C 中的卷没有标签。\n",
      " 卷的序列号是 0003-3A3E\n",
      "\n",
      " C:\\Users\\Administrator 的目录\n",
      "\n",
      "2015/11/08  14:50    <DIR>          .\n",
      "2015/11/08  14:50    <DIR>          ..\n",
      "2015/08/16  22:59    <DIR>          .android\n",
      "2015/10/08  16:45    <DIR>          .astropy\n",
      "2015/09/21  10:08    <DIR>          .config\n",
      "2015/09/09  16:03    <DIR>          .continuum\n",
      "2015/11/08  13:54    <DIR>          .ipynb_checkpoints\n",
      "2015/09/09  16:04    <DIR>          .ipython\n",
      "2015/09/21  10:08    <DIR>          .local\n",
      "2015/10/26  10:19    <DIR>          .matplotlib\n",
      "2015/10/08  16:39    <DIR>          .PyCharm40\n",
      "2015/08/15  16:17               172 .qt-license\n",
      "2015/09/21  10:11               218 .recently-used.xbel\n",
      "2015/10/20  10:02               134 .rediscli_history\n",
      "2015/11/07  16:51    <DIR>          .swt\n",
      "2015/11/07  15:31             8,309 A quick tour of IPython Notebook.ipynb\n",
      "2015/11/07  15:33           709,613 Chapter 1 - Reading from a CSV.ipynb\n",
      "2015/09/14  10:09    <DIR>          CMB\n",
      "2015/08/14  17:21    <DIR>          Contacts\n",
      "2015/10/19  14:32             7,710 datatime.ipynb\n",
      "2015/11/06  10:42    <DIR>          Desktop\n",
      "2015/11/05  10:55    <DIR>          Documents\n",
      "2015/08/14  17:21    <DIR>          Downloads\n",
      "2015/08/14  17:21    <DIR>          Favorites\n",
      "2015/11/08  14:50             8,814 ipython magic command.ipynb\n",
      "2015/08/14  17:21    <DIR>          Links\n",
      "2015/08/14  17:21    <DIR>          Music\n",
      "2015/10/19  16:13            57,402 pandas-test.ipynb\n",
      "2015/08/15  21:47    <DIR>          Pictures\n",
      "2015/10/08  16:42    <DIR>          PycharmProjects\n",
      "2015/08/14  16:55    <DIR>          Roaming\n",
      "2015/09/17  11:27        11,986,970 S1EP2_Scipy.ipynb\n",
      "2015/10/08  11:15             4,551 S1EP3_Iris.txt\n",
      "2015/08/14  17:21    <DIR>          Saved Games\n",
      "2015/08/14  17:21    <DIR>          Searches\n",
      "2015/10/15  17:03    <DIR>          Untitled Folder\n",
      "2015/10/15  17:03    <DIR>          Untitled Folder 1\n",
      "2015/10/08  16:02             8,485 Untitled.ipynb\n",
      "2015/10/08  10:44                 0 untitled.txt\n",
      "2015/08/14  17:21    <DIR>          Videos\n",
      "2015/10/23  11:32                78 zmq+redis.ipynb\n",
      "              13 个文件     12,792,456 字节\n",
      "              28 个目录 43,611,590,656 可用字节\n"
     ]
    }
   ],
   "source": [
    "# %alias为shell命令自定义简称，这个命令类似于C++里面的define ???????目前运行有问题\n",
    "%alias path (c:\\\\pythoncoding)\n",
    "!cd path\n",
    "!dir"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "系统找不到指定的路径。\n"
     ]
    }
   ],
   "source": [
    "# %bookmark 目录书签系统，用以保存常用目录的别名以实现快速跳转\n",
    "%bookmark mypath c:\\\\pythoncoding\n",
    "!cd mypath\n",
    "!dir\n",
    "#该命令与alias的区别是，bookmark会自动持久化，而alias在ipython关闭后会自动释放"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current bookmarks:\n",
      "mypath -> c:\\\\pythoncoding\n"
     ]
    }
   ],
   "source": [
    "%bookmark -l #列出所有书签"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
